package 集合0911.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;

public class Demo2 {
    public static void main(String[]args){
        Collection<Point>points1=new ArrayList<>();//集合对象
        List<Point> points2=(List<Point>) points1;
        ArrayList<Point>points3=(ArrayList<Point>) points1;
        points1.add(new Point(3,5));
        points2.add(new Point(3,5));
        points3.add(new Point(10,5));

        ArrayList<Point>p1=new ArrayList<>();//集合对象
        p1.add(new Point(100,120));//给集合中添加一个点对象
        p1.add(new Point(110,130));
        points1.addAll(p1);
        //contains 包含为true 不包含为false
        Point pt1=new Point(100,101);
        Point pt2=new Point(103,105);
        Point pt3=new Point(102,102);
        p1.add(pt1);
        p1.add(pt2);
        System.out.println(p1.contains(pt3));

        //转数组1
        Object[]arrp=points1.toArray();
        for (Object p:arrp){
            System.out.println((Point)p+"-------------");
        }
        //转数组2
        Point[] arr1=new Point[points2.size()];
        arr1=points1.toArray(arr1);
        for (Point p:arr1){
            System.out.println(p+"****");
        }

        Iterator<Point> its=points1.iterator();
        while (its.hasNext()){
            System.out.println(its.next());
        }
        System.out.println("================*");
        for (int i=0;i<points2.size();i++){
            System.out.println(points2.get(i));
        }
        System.out.println("===============+");
        for (Point p:points1){
            System.out.println(p);
        }
        System.out.println("--------------------");

    }
}
class Point{
    private int x;
    private int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}
